<template>
    <div class="container">
        <div class="box">
            <h3>用户注册</h3>
            <hr>
            <div class="content">
                <div class="item">
                    <span>账户:</span>
                    <input type="text" v-model="user.username">
                </div>
                <div class="item">
                    <span>密码:</span>
                    <input type="password" v-model="user.password">
                </div>
                <div class="item">
                    <button class="registerBtn" @click="registerApi()">注册</button>
                    <div>
                         <router-link to="/login">已有账号，去登录</router-link>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return{
            user:{
                username:'',
                password:''
            }
        }
    },
    methods:{
        async registerApi(){
            const {code,message}=await this.$api.users.register(this.user)
            if(code){
              alert(message)
              this.$router.push({
                path:'/login'
              })
            }
        }
    }
}
</script>

<style lang="scss" scoped>
    @import url('@/assets/css/reset.css');
    .container{
        position: relative;
        width: 100vw;
        height: 100vh;
        background-color: black;
        .box{
            position:absolute;
            width: 405px;
            height: 290px;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
            background-color: #fff;
            border-radius: 10px;
            h3{
                font-size: 28px;
                font-weight: normal;
                text-align: center;
                padding: 10px;
            }
            .content{
                position:absolute;
                left: 50%;
                top: 50%;
                transform: translate(-50%,-50%);
                .item{
                    line-height: 35px;
                    .registerBtn{
                        width: 100px;
                        height: 35px;
                        background-color: #0055EA;
                        color: white;
                        border-radius: 5px;
                        border: none;
                    }
                }
            }
        }
    }
</style>